<%--
  Created by IntelliJ IDEA.
  User: tjs
  Date: 2021/7/16
  Time: 19:21
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<link href="<%=path%>/static/bootstrap4.6.0/css/bootstrap.css" rel="stylesheet">
<script src="<%=path%>/static/jq/jquery-3.6.0.js"></script><!--bootstrap依赖于js所以要先导入-->
<script src="${pageContext.request.contextPath}/static/bootstrap4.6.0/js/bootstrap.bundle.js" ></script>
<h4 style="text-align: center">用户注册页面</h4>
<div class="container">
<form action="${pageContext.request.contextPath}/user/zuChe" method="get">
    <div class="form-group">
        <label>账户名</label>
        <input type="text" name="userName" id="un" placeholder="请输入6到20位账号"  class="form-control">
        <div id="nameInfo" class="text-danger" style="display: none">用户名必须6到20位</div>
    </div>
    <div class="form-group">
        <label>密码</label>
        <input type="password" name="UserPass" id="up" placeholder="请输入6到20位密码" value="${param.author}" class="form-control">
        <div id="nameInfo1" class="text-danger" style="display: none">密码必须6到20位</div>
    </div>
    <div class="form-group">
        <label>用户名</label>
        <input type="text" name="userNick" id="un1" value="${param.price}" class="form-control">
    </div>
    <div class="form-group">
        <label>电话</label>
        <input type="text" name="phone" id="p" value="${param.price}" class="form-control">
    </div>
    <div class="form-group">
        <label>地址</label>
        <input type="text" name="address" id="a" value="${param.price}" class="form-control">
    </div>
  <input type="button"  onclick="register()" class="btn btn-success" value="注册">
</form>
</div>
<script>
    function register(){
         if($("#un").val().length<6 || $("#un").val().length>20) {
             $("#nameInfo").show();
         }
      else if($("#up").val().length<6 || $("#up").val().length>20){
             $("#nameInfo").hide();
       $("#nameInfo1").show();
         }else if($("#un").val().length<6 || $("#un").val().length>20 || $("#up").val().length<6 || $("#up").val().length>20){
             $("#nameInfo1").show();
             $("#nameInfo").show();
         }

         else {
           $("#nameInfo").hide();
             $("#nameInfo1").hide();
        $.ajax({
            url:"${pageContext.request.contextPath}/user/zuChe",
            method:"get",
            data:{
                userName:$("#un").val(),
                UserPass:$("#up").val(),
                userNick:$("#un1").val(),
                phone:$("#p").val(),
                address:$("#a").val()

            },
            success:function (data) {
                if("ok"==data){
                    alert("注册成功请重新登录");
                    location.href="${pageContext.request.contextPath}/login.jsp";
                }

            }
        })
         }
    }
</script>
</div>
</body>
</html>
